package com.guinea.core.utils;

public class SqlUtils {
	static String DB_TYPE = CommonUtils.loadAppProperties().getProperty("db.type","ORACLE");

	public static String toNumber(String src) {
		if ("H2".equalsIgnoreCase(DB_TYPE))
			return "CONVERT(" + src + ",INT)";
		else
			return "TO_NUMBER(" + src + ")";
	}

	public static String formatDate(String src,String format) {
		if ("H2".equalsIgnoreCase(DB_TYPE))
			return "FORMATDATETIME(" + src + ",'"+format+"')";
		else
			return "TO_CHAR(" + src + ",'"+format+"')";
	}

	public static String nvl(String src,String defaultValue) {
		if ("H2".equalsIgnoreCase(DB_TYPE))
			return "NULLIF(" + src + ","+defaultValue+")";
		else
			return "NVL(" + src + ","+defaultValue+")";
	}
}
